
package com.mancj.slideup;

import ohos.agp.animation.Animator;
import ohos.agp.components.Component;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * <p>Default constructor for {@link SlideUp}</p>
 */
public final class SlideUpBuilder {
    /**
     * The constant M slider view
     */
    Component mSliderView;
    /**
     * The constant M density
     */
    float mDensity;
    /**
     * The constant M touchable area
     */
    float mTouchableArea;
    /**
     * The constant Location on screen x
     */
    int locationOnScreenX;

    /**
     * The constant Location on screen y
     */
    int locationOnScreenY;
    /**
     * The constant M is rtl
     */
    boolean mIsRTL;
    /**
     * The constant M start state
     */
    SlideUp.State mStartState = SlideUp.State.HIDDEN;
    /**
     * The constant M listeners
     */
    List<SlideUp.Listener> mListeners = new ArrayList<>();
    /**
     * The constant M debug
     */
    boolean mDebug = false;
    /**
     * The constant M auto slide duration
     */
    int mAutoSlideDuration = 300;
    /**
     * The constant M start gravity
     */
    int mStartGravity = Gravity.BOTTOM;
    /**
     * The constant M gestures enabled
     */
    boolean mGesturesEnabled = true;
    /**
     * The constant M hide keyboard
     */
    boolean mHideKeyboard = false;
    /**
     * The constant M interpolator
     */
    int mInterpolator = Animator.CurveType.DECELERATE;
    /**
     * The constant M also scroll view
     */
    Component mAlsoScrollView;
    /**
     * The constant M state restored
     */
    private boolean mStateRestored = false;

    /**
     * <p>Construct a SlideUp by passing the view or his child to use for the generation</p>
     *
     * @param sliderView slider view
     */
    public SlideUpBuilder(Component sliderView) {
        Internal.checkNonNull(sliderView, "View can't be null");
        mSliderView = sliderView;
        mDensity = sliderView.getResourceManager().getDeviceCapability().screenDensity / 160;
        mIsRTL = false;
    }

    /**
     * <p>Define a start state on screen</p>
     *
     * @param startState <b>(default - <b color="#EF6C00">{@link SlideUp.State#HIDDEN}</b>)</b>
     * @return the slide up builder
     */
    public SlideUpBuilder withStartState(SlideUp.State startState) {
        if (!mStateRestored) {
            mStartState = startState;
        }
        return this;
    }

    /**
     * <p>Define a start gravity, <b>this parameter affects the motion vector slider</b></p>
     *
     * @param gravity <b>(default - <b color="#EF6C00">{}</b>)</b>
     * @return the slide up builder
     */
    public SlideUpBuilder withStartGravity(int gravity) {
        if (!mStateRestored) {
            mStartGravity = gravity;
        }
        return this;
    }

    /**
     * <p>Define a {@link SlideUp.Listener} for this SlideUp</p>
     *
     * @param listeners {@link List} of listeners
     * @return the slide up builder
     */
    public SlideUpBuilder withListeners(List<SlideUp.Listener> listeners) {
        if (listeners != null) {
            mListeners.addAll(listeners);
        }
        return this;
    }

    /**
     * <p>Define a {@link SlideUp.Listener} for this SlideUp</p>
     *
     * @param listeners array of listeners
     * @return the slide up builder
     */
    public SlideUpBuilder withListeners(SlideUp.Listener... listeners) {
        List<SlideUp.Listener> listenersList = new ArrayList<>();
        Collections.addAll(listenersList, listeners);
        return withListeners(listenersList);
    }

    /**
     * <p>Turning on/off debug logging for all handled events</p>
     *
     * @param enabled <b>(default - <b color="#EF6C00">false</b>)</b>
     * @return the slide up builder
     */
    public SlideUpBuilder withLoggingEnabled(boolean enabled) {
        if (!mStateRestored) {
            mDebug = enabled;
        }
        return this;
    }

    /**
     * <p>Define duration of animation (whenever you use {@link SlideUp#hide()} or {@link SlideUp#show()} methods)</p>
     *
     * @param duration <b>(default - <b color="#EF6C00">300</b>)</b>
     * @return the slide up builder
     */
    public SlideUpBuilder withAutoSlideDuration(int duration) {
        if (!mStateRestored) {
            mAutoSlideDuration = duration;
        }
        return this;
    }

    /**
     * <p>Define touchable area <b>(in px)</b> for interaction</p>
     *
     * @param area <b>(default - <b color="#EF6C00">300dp</b>)</b>
     * @return the slide up builder
     */
    public SlideUpBuilder withTouchableAreaPx(float area) {
        if (!mStateRestored) {
            mTouchableArea = area;
        }
        return this;
    }

    /**
     * <p>Define touchable area <b>(in dp)</b> for interaction</p>
     *
     * @param area <b>(default - <b color="#EF6C00">300dp</b>)</b>
     * @return the slide up builder
     */
    public SlideUpBuilder withTouchableAreaDp(float area) {
        if (!mStateRestored) {
            mTouchableArea = area * mDensity;
        }
        return this;
    }

    /**
     * <p>Turning on/off sliding on touch event</p>
     *
     * @param enabled <b>(default - <b color="#EF6C00">true</b>)</b>
     * @return the slide up builder
     */
    public SlideUpBuilder withGesturesEnabled(boolean enabled) {
        mGesturesEnabled = enabled;
        return this;
    }

    /**
     * <p>Define behavior of soft input</p>
     *
     * @param hide <b>(default - <b color="#EF6C00">false</b>)</b>
     * @return the slide up builder
     */
    public SlideUpBuilder withHideSoftInputWhenDisplayed(boolean hide) {
        if (!mStateRestored) {
            mHideKeyboard = hide;
        }
        return this;
    }

    /**
     * <p>Define interpolator for animation (whenever you use {@link SlideUp#hide()} or {@link SlideUp#show()} methods)</p>
     *
     * @param interpolator <b>(default - <b color="#EF6C00">Decelerate interpolator</b>)</b>
     * @return the slide up builder
     */
    public SlideUpBuilder withInterpolator(int interpolator) {
        mInterpolator = interpolator;
        return this;
    }

    /**
     * parameters will be restored from this bundle, if it contains them
     *
     * @return the slide up builder
     */
    public SlideUpBuilder withSavedState() {
        return this;
    }


    /**
     * <p>Provide a {@link } that will also trigger slide events on the {@link SlideUp}.</p>
     *
     * @param alsoScrollView the other view that will trigger the slide events
     * @return the slide up builder
     */
    public SlideUpBuilder withSlideFromOtherView(Component alsoScrollView) {
        mAlsoScrollView = alsoScrollView;
        return this;
    }

    /**
     * <p>Build the SlideUp and add behavior to view</p>
     *
     * @return the slide up
     */
    public SlideUp build() {
        return new SlideUp(this);
    }

}